﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace ActionFilter1
{
    public class MyActionFilter2 : IAsyncActionFilter
    {
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            //之前
            Console.WriteLine("MyActionFilter2:前代码");
            ActionExecutedContext result=await next();//下一个ActionFilter
            //之后
            if (result.Exception!=null) //得到返回值,判断是否执行成功
            {
                Console.WriteLine("MyActionFilter2:发生异常了");
            }
            else
            {
                Console.WriteLine("MyActionFilter2:执行成功");
            }
        }
    }
}
